package com.common.app.db

import androidx.room.*
import com.common.app.data.bean.SearchHistoryModel

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2022/8/21
 * <p>
 * 描述：搜索历史Dao类
 * <p>
 * 修订历史：
 */
@Dao
interface SearchHistoryModelDao {

    // 插入
    @Insert
    fun insert(vararg event: SearchHistoryModel)

    // 删除
    @Delete
    fun delete(list: MutableList<SearchHistoryModel>)

//    // 删除
//    @Delete
//    fun deleteAll(list: MutableList<SearchHistoryModel>)

    //删除所有 → '所有'的只能用@Query,@Query可以编写任意的sql语句
    @Query("DELETE FROM search_history")
    fun deleteAll()

    // 查询
    @Query("select * from search_history")
    fun findAll(): MutableList<SearchHistoryModel>

    // 查询是否存在
    @Query("SELECT EXISTS (SELECT 1 FROM search_history WHERE searchKey = :searchKey)")
    fun isExistModel(searchKey: String?): Boolean

    @Query("select count(*) from search_history")
    fun count(): Int

    // 修改
    @Update
    fun update(event: SearchHistoryModel)

    @Query("select * from search_history WHERE searchKey =:searchKey")
    fun findByKeyItem(searchKey: String): SearchHistoryModel

    @Query("select * from search_history WHERE searchKey =:searchKey")
    fun findByKey(searchKey: String): MutableList<SearchHistoryModel>

    // 查询 所有  倒序 查询
    @Query("SELECT * FROM search_history ORDER BY ID DESC  LIMIT :mSize")
    fun findByDescSize(mSize: Int): MutableList<SearchHistoryModel>
}